package gui;

public class Fade extends Thread {
	
	View view = null;
	
	char direction;
	
	boolean fadeIn = false;
	
	public Fade(View view, boolean fadeIn, char direction) {
		this.view = view;
		this.fadeIn = fadeIn;
		this.direction = direction;
	}

	@Override
	public void run() {
		while((Boolean) view.getFade()[0]) {
			if (!fadeIn) {	
				if ((Integer) view.getFade()[1] < 255) {
					view.setFade(true, (Integer) view.getFade()[1]+1);
					view.repaint();
				} else {
					view.finishLoading(direction);
					break;
				}
			} else {
				if ((Integer) view.getFade()[1] > 0) {
					view.setFade(true, (Integer) view.getFade()[1]-1);
					view.repaint();
				} else {
					view.setFade(false, 0);
					break;
				}
			}
			try {
				Thread.sleep(5);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
}